package com.xy.iot.common.enums;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

/**
 * @author Administrator
 * @create 2018-05-08 10:08
 * @desc 消息格式枚举
 */
@Getter
public enum MessageFormatDataEnum {
	GBK(4, "GBK格式"),
	UTF_8(3, "UTF-8格式"),
	JSON(2, "JSON格式"),
	ASCII(1, "ASCII格式"),
	HEX(0, "HEX 格式"),

	;
	@ApiModelProperty("枚举唯一标识")
	private final Integer key;
	@ApiModelProperty("枚举描述")
	private final String value;
	/**
	 * 创建消息格式枚举，构造方法
	 * @param key 枚举唯一标识
	 * @param value 枚举描述
	 */
	private MessageFormatDataEnum(Integer key, String value) {
		this.key = key;
		this.value = value;
	}


	/**
	 * 根据枚举唯一标识获取枚举
	 * @param key 枚举唯一标识
	 * @return
	 */
	public static MessageFormatDataEnum getMessageFormatDataEnum(Integer key) {
		for (MessageFormatDataEnum messageFormatDataEnum : MessageFormatDataEnum.values()) {
			if (messageFormatDataEnum.getKey().equals(key)) {
				return messageFormatDataEnum;
			}
		}
		return null;
	}

}
